// pages/payment-success/success.js
var app = getApp()
var request = require('../../utils/request');
var utils = require('../../utils/utils');

// var shareContent = {
//     'title':'企鹅优品-优质生活指南',
//     'desc':'腾讯精品体验平台，为用户提供优质的生活方式和购物体验。',
//     'path':'/pages/project-index/index'
// }
// var shareObj = utils.share(shareContent);
var pageSetting = {
    data: {
        isShowElectInvoice : false,
        isShowMask : true,
        retData : {},
        offOrderId:'',
        offlineRetData:{},
        salesForm: 0,
        offlineSalesForm:''
    },
    /*onShareAppMessage: function () {
        var that = this;       
        return {
          title: '企鹅优品-优质生活指南',
          desc: '腾讯精品体验平台，为用户提供优质的生活方式和购物体验。',
          path: '/pages/project-index/index',
          success:function(res){
              that.setData({
                  isShowMask : false
              })
          },
          fail:function(res){
            that.setData({
              isShowMask : false
            })
           }
         } 
       
        
    },*/
    onLoad:function(options){
        var that = this;
        var orderId = options.order_id;
        var offlineSalesForm = options.offlineSalesForm
        var retData = this.data['retData'];
        var data = {
            'dp:api:act:success':{
                'order_id':orderId
            }
        };
        that.setData({
          offOrderId:options.order_id ,
          offlineSalesForm:offlineSalesForm[0] 
        })
        request.post({
          path: '/wxapp_api/api'
        },data)
        .then(function(res){
            retData = res['dp:api:act:success'];
            console.log(retData)
                 
            if(retData.ret != 0){
                wx.navigateTo({
                    url: "../error/error"
                })
            }
            if(retData.ret == 0){
                var salesForm = that.data.salesForm;
                salesForm = retData.data.order_form;
                if(retData.data.pay_status == 1){
                    if(retData.data.public_operator){
                        that.setData({
                            retData : retData,
                            salesForm : salesForm
                        })    
                    }else{
                        that.setData({
                            retData : retData,
                            salesForm : salesForm
                        })
                    }
                    
                }    
            }
        });
    },
    successTap:function(){
        wx.navigateBack({
            delta: 5
        }) 
    },
    hideMask:function(){
        this.setData({
            isShowMask : false
        });
    },
    showElectInvoice:function(){
       var that = this;
       var offlineOrderId = that.data.offOrderId;
       var isShowElectInvoice = that.data.isShowElectInvoice;
       var offLineData = {
            'dp:api:act:orderinvoice':{
                'order_id':offlineOrderId
            }
    };
    request.post({
          path: '/wxapp_api/api'
        },offLineData)
        .then(function(res){
             var offlineRetData = res['dp:api:act:orderinvoice'];
             console.log(offlineRetData);
             offlineRetData.data.project_list=(offlineRetData.data.project_list).join(' ')
            if(offlineRetData.ret==0){
                isShowElectInvoice = true;
                that.setData({

                            offlineRetData : offlineRetData,
                            isShowElectInvoice : isShowElectInvoice
                    })
            }
    });

    console.log(that.data.isShowElectInvoice);

},
closeElectInvoice:function(){
    this.setData({
            isShowElectInvoice : false
         })
   }
};
utils.assign(pageSetting);
Page(pageSetting);